//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Tathata.Common.Caching;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Globalization;
using Tathata.Common.DAL;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.DAL.Managers;

namespace Tathata.Common.BLL.Managers
{
    /// <summary>
    /// Specification attribute manager
    /// </summary>
    public class SpecificationAttributeManager
    {
        #region Constants
        private const string SPECIFICATIONATTRIBUTE_BY_ID_KEY = "Nop.SpecificationAttributes.id-{0}";
        #endregion

        #region Methods
        /// <summary>
        /// Gets a specification attribute
        /// </summary>
        /// <param name="SpecificationAttributeID">The specification attribute identifier</param>
        /// <returns>Specification attribute</returns>
        public static SpecificationAttribute GetBySpecificationAttributeID(int SpecificationAttributeID)
        {
            string key = string.Format(SPECIFICATIONATTRIBUTE_BY_ID_KEY, SpecificationAttributeID);
            object obj2 = NopCache.Get(key);
            if (NopContext.IsCachable && (obj2 != null))
            {
                return (SpecificationAttribute)obj2;
            }

            SpecificationAttribute specificationAttribute = SpecificationAttributeDBManager.GetBySpecificationAttributeID(SpecificationAttributeID);

            if (NopContext.IsCachable)
            {
                NopCache.Max(key, specificationAttribute);
            }
            return specificationAttribute;
        }

        /// <summary>
        /// Deletes a specification attribute
        /// </summary>
        /// <param name="SpecificationAttributeID">The specification attribute identifier</param>
        public static void DeleteSpecificationAttribute(int SpecificationAttributeID)
        {
            SpecificationAttributeDBManager.DeleteSpecificationAttribute(SpecificationAttributeID);
            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(SPECIFICATIONATTRIBUTE_BY_ID_KEY);
            }
        }

        /// <summary>
        /// Gets specification attribute collection
        /// </summary>
        /// <returns>Specification attribute collection</returns>
        public static SpecificationAttributeCollection GetSpecificationAttributes()
        {
            return SpecificationAttributeDBManager.GetSpecificationAttributes();
        }

        /// <summary>
        /// Inserts a specification attribute
        /// </summary>
        /// <param name="Name">The name</param>
        /// <returns>Specification attribute</returns>
        public static SpecificationAttribute InsertSpecificationAttribute(string Name)
        {
            SpecificationAttribute specificationAttribute = SpecificationAttributeDBManager.InsertSpecificationAttribute(Name);

            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(SPECIFICATIONATTRIBUTE_BY_ID_KEY);
            }

            return specificationAttribute;
        }

        /// <summary>
        /// Updates the specification attribute
        /// </summary>
        /// <param name="SpecificationAttributeID">The specification attribute identifier</param>
        /// <param name="Name">The name</param>
        /// <returns>Specification attribute</returns>
        public static SpecificationAttribute UpdateSpecificationAttribute(int SpecificationAttributeID, string Name)
        {
            SpecificationAttribute specificationAttribute = SpecificationAttributeDBManager.UpdateSpecificationAttribute(SpecificationAttributeID, Name);

            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(SPECIFICATIONATTRIBUTE_BY_ID_KEY);
            }

            return specificationAttribute;
        }

        #endregion
    }
}
